package com.weimob.mcloud.wechatwork.customer.export;

import com.weimob.mcloud.wechatwork.customer.mq.product.TagChangeMsgProduct;
import com.weimob.mcloud.wechatwork.customer.service.TagManageService;
import com.weimob.mcloud.wechatwork.customer.service.user.module.bo.tag.CustomerMarkTagFailBO;
import com.weimob.mcloud.wechatwork.customer.service.user.module.bo.tag.MarkTagInfoBO;
import com.weimob.mcloud.wechatwork.customer.service.user.module.bo.tag.TagBO;
import com.weimob.mcloud.wechatwork.customer.service.user.module.bo.tag.TagItemBO;
import com.weimob.mcloud.wechatwork.customer.service.user.module.dto.customer.ExternalUserInfoFindDTO;
import com.weimob.mcloud.wechatwork.customer.service.user.module.dto.customer.MarkTagInfoDTO;
import com.weimob.mcloud.wechatwork.customer.service.user.module.dto.tag.CustomerTagDTO;
import com.weimob.mcloud.wechatwork.customer.service.user.module.msgBody.CorpCustomerTagChangeBody;
import com.weimob.mcloud.wechatwork.customer.service.user.module.msgBody.TagChangeBody;
import com.weimob.mcloud.wechatwork.customer.service.user.module.req.tag.CustomerTagQueryDTO;
import com.weimob.mcloud.wechatwork.customer.service.user.module.req.tag.MarkTagDTO;
import com.weimob.mcloud.wechatwork.customer.service.user.module.req.tag.TagQueryDTO;
import com.weimob.mcloud.wechatwork.customer.service.user.service.TagClient;
import com.weimob.mcloud.wechatwork.customer.service.user.utils.SoaResponseUtil;
import com.weimob.soa.common.response.SoaResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author junlong.lv
 * @version 1.0
 * @date 2021/10/26 6:57 下午
 */
@Service
public class TagClientImpl implements TagClient {

    @Autowired
    private TagManageService tagManageService;

    @Autowired
    private TagChangeMsgProduct tagChangeMsgProduct;

    @Override
    public SoaResponse<Boolean, ?> markTag(MarkTagDTO markTagBOReq) {
        return tagManageService.markTag(markTagBOReq);
    }

    @Override
    public SoaResponse<TagItemBO, ?> queryTagByProductInstanceId(TagQueryDTO tagQueryBOReq) {
        return SoaResponseUtil.ok(tagManageService.queryTagByProductInstanceId(tagQueryBOReq));
    }

    @Override
    public SoaResponse<List<TagBO>, ?> queryCustomerTag(CustomerTagQueryDTO customerTagQueryDTO) {
        return SoaResponseUtil.ok(tagManageService.queryCustomerTag(customerTagQueryDTO));
    }

    /**
     * 添加客户标签
     * 必须交验删除
     * 1、校验客户不能为空
     * 2、员工可以为空串，因为有些渠道打的标签是拿不到员工id的
     * 3、校验标签不能为空
     * 4、校验标签组不能为空
     * @param customerTagDTO
     * @return
     */
    @Override
    public SoaResponse<Boolean, ?> addCustomerTag(CustomerTagDTO customerTagDTO) {
        return tagManageService.addCustomerTag(customerTagDTO);
    }

    /**
     * 移除客户标签不需要校验线束
     * 可以根据一下条件删除
     * 1、根据标签删除
     * 2、根据标签组删除
     * 3、根据员工删除
     * 4、根据客户删除
     * @return
     */
    @Override
    public SoaResponse<Boolean, ?> removeCustomerTag(CustomerTagDTO customerTagDTO) {
        return tagManageService.removeCustomerTag(customerTagDTO, false);
    }

    @Override
    public SoaResponse<Boolean, ?> sendTagChangeMsg(TagChangeBody tagChangeBody) {
        tagChangeMsgProduct.sendTagChangeMsg(tagChangeBody);
        return SoaResponseUtil.ok(true);
    }

    @Override
    public SoaResponse<Boolean, ?> sendCorpCustomerTagChangeBody(CorpCustomerTagChangeBody corpCustomerTagChangeBody) {
        tagChangeMsgProduct.sendCorpCustomerTagChangeBody(corpCustomerTagChangeBody);
        return SoaResponseUtil.ok(true);
    }

    @Override
    public SoaResponse<Boolean, Void> batchMarkTag(ExternalUserInfoFindDTO externalUserInfoListDTO) {
        return SoaResponseUtil.ok(tagManageService.batchMarkTag(externalUserInfoListDTO));
    }

    @Override
    public SoaResponse<Boolean, Void> batchRemoveTag(ExternalUserInfoFindDTO externalUserInfoListDTO) {
        return SoaResponseUtil.ok(tagManageService.batchRemoveTag(externalUserInfoListDTO));
    }

    @Override
    public SoaResponse<MarkTagInfoBO, Void> queryMarkTagInfo(MarkTagInfoDTO markTagInfoDTO) {
        return SoaResponseUtil.ok(tagManageService.queryMarkTagInfo(markTagInfoDTO));
    }

    @Override
    public SoaResponse<Boolean, Void> readMarkTagInfo(MarkTagInfoDTO markTagInfoDTO) {
        return SoaResponseUtil.ok(tagManageService.readMarkTagInfo(markTagInfoDTO));
    }


    @Override
    public SoaResponse<Boolean, Void> exportMarkTagFail(MarkTagInfoDTO markTagInfoDTO) {
        return SoaResponseUtil.ok(tagManageService.exportMarkTagFail(markTagInfoDTO));
    }

    @Override
    public SoaResponse<Long, Void> count(MarkTagInfoDTO markTagInfoDTO) {
        return SoaResponseUtil.ok(tagManageService.count(markTagInfoDTO));
    }

    @Override
    public SoaResponse<List<CustomerMarkTagFailBO>, Void> queryMarkTagFailInfoExport(MarkTagInfoDTO markTagInfoDTO) {
        return SoaResponseUtil.ok(tagManageService.queryMarkTagFailInfoExport(markTagInfoDTO));
    }
}
